#include <iostream>
#include <cstring>
using namespace std;

const int N = 510;
const int INF = 0x3f3f3f3f;

int n;
int a[N][N];    //输入数字三角形
int f[N][N];    //状态表示数组
int res = -INF; //用来底层选最大

int main()
{
    freopen("cin.txt", "r", stdin);
    memset(f, -0x3f, sizeof f); //先将所有点都初始化为极小
    cin >> n;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= i; ++j)
            cin >> a[i][j];
    f[1][1] = a[1][1];           //顶端没得走
    for (int i = 2; i <= n; ++i) //注意，这里从第二层开始才有得走
        for (int j = 1; j <= i; ++j)
            f[i][j] = max(f[i - 1][j] + a[i][j], f[i - 1][j - 1] + a[i][j]); //这里不用担心边缘值，因为越界的值都是极小值，根本没办法进行计算
    for (int i = 1; i <= n; ++i)                                             //底层比大小
        res = max(res, f[n][i]);
    cout << res;
    return 0;
}